import java.net.*;
import java.io.*;

public class URLFileReceiver {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		String str = "http://rocksvv.cs.uit.no:9909/?servernumber=";
		int serverNum = 1;
		String clientHostname = "tile-1-1";
		str = str + serverNum + "client=" + clientHostname;
		String req = "http://rocksvv.cs.uit.no:9909/045.jpg";
		URL yahoo = new URL(req);
        URLConnection yc = yahoo.openConnection();
        InputStream inputStream = yc.getInputStream();
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("zw.jpg"));
		BufferedInputStream bis = new BufferedInputStream(inputStream);
		byte[] content = new byte[1024];
		int r; 
		int bytesRead = 0;
		while( (r = bis.read(content)) != -1){
			bos.write(content, 0, r);
			bytesRead+=r;
			if(bytesRead == 250880){
				System.out.println(r);
			}
		}
		bos.close();
		System.out.println(bytesRead);

	}

}
